package com.thrift.server.rpc.impl;

import com.thrift.server.annotation.ThriftServer;
import com.thrift.server.rpc.thriftcode.DataException;
import com.thrift.server.rpc.thriftcode.Student;
import com.thrift.server.rpc.thriftcode.StudentService;
import com.thrift.server.service.impl.StudentServiceImpl;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 何锦涛--CodeSleep
 * @since 2022/9/4 14:48
 */
@Service
@ThriftServer(port = 8300, serviceName = "Thrift-Server")
public class ServerServiceImpl implements StudentService.Iface {

    @Autowired
    private StudentServiceImpl studentService;

    @Override
    public Student getStudentByName(String name) throws DataException, TException {
        com.thrift.server.entity.Student studentByName = studentService.getStudentByName(name);
        Student student = new Student();
        student.address = studentByName.getAddress();
        student.name = studentByName.getName();
        student.setAge(studentByName.getAge());
        return student;
    }

    @Override
    public void saveStudent(Student student) throws DataException, TException {
        com.thrift.server.entity.Student student1 = new com.thrift.server.entity.Student();
        student1.setName(student.name);
        student1.setAddress(student.address);
        student1.setAge(student.age);
        studentService.saveStudent(student1);
    }
}
